	//域名
	const baseUrl = 'https://3252.srkjapp.com'
	let HTTP_REQUEST_URL = baseUrl
	let HTTP_REQUEST_URL_IMG = baseUrl + '/srapi/home/upload'

	function toLogin() {
		uni.navigateTo({
			url: '/pages/login/login?type=1',
		})
	}
	/**
	 * 发送请求
	 */
	function baseRequest(url, method, data, {
		noAuth = false,
		noVerify = false
	}) {
		let header = {
			'XX-Token': '',
			'XX-Device-Type': 'wxapp',
		}
		let is_phone = uni.getStorageSync('phone') || ''
		if (!noAuth) {
			//登录过期自动登录
			if (!is_phone) {
				toLogin()
				return uni.showToast({
					title: '未登录',
					icon: 'error',
					mask: true,
					duration: 1000,
				})
			}
		}
		return new Promise((reslove, reject) => {
			uni.showLoading({
				mask: true,
			})
			uni.request({
				url: HTTP_REQUEST_URL + url,
				method: method || 'GET',
				header: header,
				data: {
					uid: uni.getStorageSync('uid'),
					...data
				},
				success: (res) => {
					uni.hideLoading()
					// console.log('成功', res.data);
					// 不需要判断是否正确
					if (noVerify) {
						reslove(res.data, res)
					} else if (res.data.code == 0) {
						reslove(res.data, res)
					} else if (res.data.code == 1) {
						uni.showToast({
							mask: true,
							title: res.data.msg,
							icon: 'none',
							duration: 1000,
						})
						reject(res.data, res)
					} else if (res.data.code == 401) {
						uni.clearStorageSync()
						uni.showToast({
							mask: true,
							title: res.data.msg,
							icon: 'none',
							duration: 1000,
						})
						setTimeout(() => {
							uni.reLaunch({
								url: '/pages/login/login',
							})
						}, 500) // 1秒后执行打印功能
					} else if (res.data.code == 402) {
						uni.clearStorageSync()
						uni.showToast({
							mask: true,
							title: res.data.msg,
							icon: 'none',
							duration: 1000,
						})
						setTimeout(() => {
							uni.reLaunch({
								url: '/pages/login/login',
							})
						}, 500) // 1秒后执行打印功能
					} else {
						reject(res.data.msg || '系统错误')
					}
				},
				fail: (msg) => {
					uni.hideLoading()
					// console.log('失败', res.data);
					let data = {
						mag: '请求失败',
						status: 1, //1没网
					}
					// #ifdef APP-PLUS
					reject(data)
					// #endif
					// #ifndef APP-PLUS
					reject('请求失败')
					// #endif
				},

			})
		})
	}

	const request = {
		HTTP_REQUEST_URL_IMG,
	}

	;
	['options', 'get', 'post', 'put', 'head', 'delete', 'trace', 'connect'].forEach((method) => {
		request[method] = (api, data, opt) => baseRequest(api, method, data, opt || {})
	})

	export default request